package Decorator;
//装饰者模式
public class DecoratorPattern {
    public static void main(String[] args) {
        Component component = new ConcreteComponent();
        component.operation();
        System.out.println("------------");
        Component component1 = new ConcreteDecorator(component);
        component1.operation();
    }
}
//抽象构件
interface Component{
    public void operation();
}
//具体构件
class ConcreteComponent implements Component{
    public ConcreteComponent() {
        System.out.println("生成具体构件角色");
    }

    @Override
    public void operation() {
        System.out.println("调用具体构件角色操作");
    }
}
//抽象装饰
class Decorator implements Component{
    private Component component;

    public Decorator(Component component) {
        this.component = component;
    }

    @Override
    public void operation() {
        component.operation();
    }
}
//具体装饰
class ConcreteDecorator extends Decorator{

    public ConcreteDecorator(Component component) {
        super(component);
    }
    public void operation(){
        super.operation();
        addOperation();
    }
    public void addOperation(){
        System.out.println("为具体构件角色增加额外方法");
    }
}